﻿@{
    ViewData["Title"] = "Home Page";
    Layout = "_Layout";
    var awardpunish = Model;

}

<fieldset class="layui-elem-field" style="margin: 20px">
    <legend>奖惩申请提交表</legend>
    <div class="layui-field-box">
        <form class="layui-form  layui-form-pane" action="" lay-filter="example">
            <div class="layui-form-item">
                <label class="layui-form-label">申请标题</label>
                <div class="layui-input-block">
                    <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input" id="title">
                </div>
            </div>


            <div class="layui-row layui-col-space5">
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">学生学号</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入学生学号" class="layui-input" id="studentid">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">

                    <div class="layui-form-item">
                        <label class="layui-form-label">奖惩内容 </label>
                        <div class="layui-input-block">
                            <select name="interest2" lay-filter="aihao2" id="punishcontent">
                                <option value="-1"></option>
                                <option value="0">警告</option>
                                <option value="1">记过</option>
                                <option value="2">留校查看</option>
                                <option value="3">开除</option>
                                <option value="4">申请奖励</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">奖励内容</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入奖励名称" class="layui-input" id="awardcontent">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">具体内容</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea" name="desc" id="APcontent"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">

                    <input type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1" id="addAp" value="火速提交" />
                </div>
            </div>
        </form>
    </div>
</fieldset>



@section Scripts{
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="~/layui-v2.5.5/layui/layui.all.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script>

        $("#addAp").on("click", function () {

            var gettitle = $("#title").val();
            var getstudent = $("#studentid").val();
            var getpunish = $("#punishcontent option:selected").val();
            var getaward = $("#awardcontent").val();
            var getAP = $("#APcontent").val();

            $.ajax({
                url: '/Api/AddAwardPunishment2',
                type: "post",
                DataType: "json",
                data: {
                    'Title': gettitle,
                    'Sid': getstudent,
                    'PunishContent': getpunish,
                    'AwardContent': getaward,
                    'Content': getAP
                },
                success: function (data) {
                    //data.msg;
                    alert(data.msg);
                }
            })
            return false;
        });//提交奖惩申请
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;

            laydate.render({
                elem: '#test16'
                , type: 'datetime'
                , range: '到'
                , format: 'yyyy年M月d日H时m分s秒'
            });


            //日期
            laydate.render({
                elem: '#date'
            });
            laydate.render({
                elem: '#date1'
            });

            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo_editor');

            //自定义验证规则
            form.verify({
                title: function (value) {
                    if (value.length < 1) {
                        return '标题至少得1个字符啊';
                    }
                }
                , pass: [
                    /^[\S]{6,12}$/
                    , '密码必须6到12位，且不能出现空格'
                ]
                , content: function (value) {
                    layedit.sync(editIndex);
                }
            });

            //监听提交
            form.on('submit(demo1)', function (data) {
                layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                })
                return false;
            });


            ////表单取值
            //layui.$('#LAY-component-form-getval').on('click', function(){
            //  var data = form.val('example');
            //  alert(JSON.stringify(data));
            //});

        });


    </script>
}